﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class UsergroupsDAO:IData<Usergroups> 
 	{
		public UsergroupsDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Usergroups item, int t) {
			 return connec.ExecuteNonQuery("sp_Usergroups", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Usergroups.c_id, item.id), new SqlParameter("@" + Usergroups.c_groupName, item.groupName),
				 new SqlParameter("@" + Usergroups.c_description, item.description), new SqlParameter("@" + Usergroups.c_isActive, item.isActive)); 
		}

		public override Usergroups GetItem(IDataReader dr)
		{
			Usergroups obj = new Usergroups();
			obj.id = Convert.ToInt32(dr[Usergroups.c_id]);
			obj.groupName = Convert.ToString(dr[Usergroups.c_groupName]);
			obj.description = Convert.ToString(dr[Usergroups.c_description]);
			obj.isActive = Convert.ToInt32(dr[Usergroups.c_isActive]);
			return obj;
		}

		public override List<Usergroups> GetAll()
		{
			return GetAll("select * from " + Usergroups.b_Usergroups, CommandType.Text);
		}

		public override Usergroups GetItemById(object id)
		{
            return this.GetAll().FirstOrDefault(x => x.id == (int)id);
		}

	}

 }
